import type {ShallowRef} from 'vue';
import {onMounted,onUnmounted} from 'vue';
import {throttle,operateDom} from '../../../util';

export default function(
	rootDom:ShallowRef<HTMLElement>,
	getSizeObject:() => void,
	time:number|false,
){
	const callback=operateDom(getSizeObject);
	const emitEvent=time===false?callback:throttle(callback,time||undefined);
	const observer=new ResizeObserver(emitEvent);
	onMounted(() => {
		observer.observe(rootDom.value,{box:'border-box'});
	});
	onUnmounted(() => {
		observer.disconnect();
	});
}